import { BasicForm } from '@/components/ProForm/interface/index';
import { PublicInterface } from '@/interface/public';
import { UserInterface } from '@/api/interface/auth/user';

export function useChangePwdForm(proTableBox: PublicInterface.ProTableValue) {
  let changePwdForm = reactive<BasicForm<UserInterface.ReqAdminChangeUserByPwd>>({
    form: {
      account: '',
      password: ''
    },
    title: '用户',
    visible: false,
    formCols: 1,
    options: [
      {
        type: 'input',
        label: '账号',
        hide: false,
        prop: 'account',
        defaultValue: '',
        rules: [{ required: true, message: '账号不能为空', trigger: 'blur' }],
        attrs: {
          disabled: true
        }
      },
      {
        type: 'input',
        label: 'password',
        hide: false,
        defaultValue: '',
        prop: 'password',
        rules: [{ required: true, message: 'password', trigger: 'blur' }]
      }
    ]
  });

  const savePwdForm = async (form: UserInterface.ReqAdminChangeUserByPwd) => {
    await userAdminChangeUserByPwd(form);
    changePwdForm.visible = false;
    elMessage();
    proTableBox.value?.getTableList();
  };
  return {
    changePwdForm,
    savePwdForm
  };
}
